<?php

/**
 * urCron actions.
 *
 * @package    urCron
 * @author     Marc Weistroff
 * @version    
 */
class urCronFeedActions extends baseUrCronActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $webUpdater = sfConfig::get('app_ur_cron_web_updater', 'on');
    if($webUpdater == 'on' || $webUpdater == true || $webUpdater == 'true')
      urCron::getInstance()->doCronJob();
    
    $query = Doctrine::getTable('urCronItem')->getQueryForPager();
    $this->pager = new sfDoctrinePager('urCronItem');
    $this->pager->setQuery($query);

    if($request->getParameter('sf_format') == "html")
    {
      $this->getResponse()->setTitle('future is gonna be');

      $this->pager->setMaxPerPage(sfConfig::get('app_ur_cron_pagination_max_per_page_feed_index'));
      $this->pager->setPage($request->getParameter('page', 1));

      $this->route = "homepage";
      $this->feed = null;
    }
    else
    {
      $this->lastUpdatedAt = Doctrine::getTable('urCronFeed')->getLastUpdatedFeed()->getUpdatedAt();
      $this->pager->setPage(1);
      $this->pager->setMaxPerPage(sfConfig::get('app_ur_cron_pagination_max_per_page_feed_syndication'));
    }
    $this->pager->init();

    $this->setTemplate('feedIndex');

  }

  public function executeShow(sfWebRequest $request)
  {
    $this->feed = $this->getRoute()->getObject();
    $this->forward404unless($this->feed);
    $query = Doctrine::getTable('urCronItem')->getQueryForFeedPager($this->feed->getId());

    $this->pager = new sfDoctrinePager('urCronItem');
    $this->pager->setQuery($query);
    $this->pager->setMaxPerPage(sfConfig::get('app_ur_cron_pagination_max_per_page_feed_show'));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
    $this->route = "urCronFeed_show";

    $this->getResponse()->setTitle($this->feed->getName() . ' > future is gonna be');
    
    $this->setTemplate('index');
  }

  public function executeShowTagged(sfWebRequest $request)
  {
    $tag = $this->getRoute()->getObject();
    $this->forward404unless($tag);

    $query = Doctrine::getTable('urCronItem')->getQueryForTagPager($tag->getId());

    $this->pager = new sfDoctrinePager('urCronItem', 1);
    $this->pager->setQuery($query);
    $this->pager->setMaxPerPage(8);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();

    $this->setTemplate('index');
  }
}
